package com.qiyun.erp.util.listener;

import com.qiyun.erp.auth.res.business.ebi.ResEbi;
import com.qiyun.erp.auth.res.vo.ResModel;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.List;

public class AllReloadListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext sc = servletContextEvent.getServletContext();
        WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
        ResEbi resEbi = (ResEbi) ctx.getBean("resEbi");
        List<ResModel> resList = resEbi.getAll();
        StringBuilder sb = new StringBuilder();
        for (ResModel temp : resList) {
            sb.append(temp.getUrl());
            sb.append(",");
        }
        //放入前后文中
        sc.setAttribute("allRes", sb.toString());
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
